package com.iot08.api.controller;

import com.iot08.api.annotation.CheckAppSign;
import com.iot08.api.controller.base.BaseController;

import com.iot08.api.service.GoldCoinService;
import com.iot08.api.vo.request.*;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;


/**
 * @author cwj
 * @description
 * @date 2025/3/5 17:26
 **/
@RestController
@RequestMapping("getway/goldCoin")
@Slf4j
public class GoldCoinController extends BaseController {

    @Resource
    private GoldCoinService goldCoinService;

    /**
     * @description 查询金币套餐信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/6 9:39
     **/
    @GetMapping("/query")
    public ResponseMap queryGoldCoin(@Validated BaseAccountReqVO vo) {
        //获取版本信息
        VersionVo versionVo = obtainVersionInfo(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
        return goldCoinService.queryGoldCoin(versionVo,vo.getOpenid());
    }


    /**
     * @description 金币购买服务，已经作废
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/13 14:20
     **/
    @PostMapping("/buy")
    @CheckAppSign
    public ResponseMap buyServer(@Validated @RequestBody GoldCoinBuyServerReqVo vo){
        return goldCoinService.buyServer(vo.getBodyForm());
    }

    /**
     * @description 增加金币信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/7 10:58
     **/
    @PostMapping("/add")
    public ResponseMap addGoldCoin(@Validated @RequestBody GoldCoinAddReqVo vo){
          return goldCoinService.addGoldCoin(vo);
    }

    /**
     * @description 修改金币信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/7 10:59
     **/
    @PostMapping("/edit")
    public ResponseMap addGoldCoin(@Validated @RequestBody GoldCoinEditReqVo vo){
        return goldCoinService.editGoldCoin(vo);
    }
}
